﻿using CoffeeShop.DAO;
using CoffeeShop.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CoffeeShop.BIZ
{
    public class TableBiz
    {
        private TableDao _tableDao = new TableDao();

        /// <summary>
        /// Convert param to Table object
        /// </summary>
        /// <param name="officeName"></param>
        /// <param name="officeAddress"></param>
        /// <param name="officePhone"></param>
        /// <returns></returns>
        public Table ConvertToTableObject(string tableName, int officeId, int areaId, int tableId = 0, bool isDeleted = false)
        {
            Table table = new Table();
            table.TableId = tableId;
            table.Name = tableName;
            table.AreaId = areaId;
            table.OfficeId = officeId;
            table.IsDeleted = isDeleted;
            return table;
        }

        /// <summary>
        /// Get all table
        /// </summary>
        /// <returns></returns>
        public List<Table> GetAllTables()
        {
            return _tableDao.GetAllTables();
        }
        /// <summary>
        /// Get table by TableId
        /// </summary>
        /// <param name="tableId">TableId</param>
        /// <returns>Table object</returns>
        public Table GetTableById(int tableId)
        {
            return _tableDao.GetTableById(tableId);
        }

        /// <summary>
        /// Get a Table by TableName, OfficeId, AreaId
        /// </summary>
        /// <param name="tableName">TableName</param>
        /// <param name="officeId">OfficeId</param>
        /// <param name="areaId">AreaId</param>
        /// <returns>Table object</returns>
        public Table GetTableOfOffice(string tableName, int officeId, int areaId)
        {
            return _tableDao.GetTableOfOffice(tableName, officeId, areaId);
        }

        /// <summary>
        /// Create a new table
        /// </summary>
        /// <param name="table">Table object</param>
        /// <returns>True: Success --- False: Fail</returns>
        public bool CreateTable(Table table)
        {
            return _tableDao.CreateTable(table);
        }

        /// <summary>
        /// Update a table
        /// </summary>
        /// <param name="table">Table object</param>
        /// <returns>True: Success --- False: Fail</returns>
        public bool UpdateTable(Table table)
        {
            return _tableDao.UpdateTable(table);
        }

        /// <summary>
        /// Delete a table
        /// </summary>
        /// <param name="tableId">TableId</param>
        /// <returns>True: Success --- False: Fail</returns>
        public bool DeleteTable(int tableId)
        {
            return _tableDao.DeleteTable(tableId);
        }

        /// <summary>
        /// Check is duplicate table when create a new table
        /// </summary>
        /// <param name="tableName">TableName</param>
        /// <param name="officeId">OfficeId</param>
        /// <param name="areaId">AreaId</param>
        /// <returns>True: Existed --- False: Not Existed</returns>
        public bool IsDuplicateTableCreate(string tableName, int officeId, int areaId)
        {
            Table table = new Table();
            table = _tableDao.GetTableOfOffice(tableName, officeId, areaId);
            if (table != null)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Check is duplicate Table when update a table
        /// </summary>
        /// <param name="tableId">TableId</param>
        /// <param name="tableName">TableName</param>
        /// <param name="officeId">OfficeId</param>
        /// <param name="areaId">AreaId</param>
        /// <returns>True: Existed --- False: Not Existed</returns>
        public bool IsDuplicateTableWhenUpdate(int tableId, string tableName, int officeId, int areaId)
        {
            return _tableDao.IsDuplicateTableWhenUpdate(tableId, tableName, officeId, areaId);
        }
    }
}